import java.util.*;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: dings
 * Date: 2024-07-22
 * Time: 23:41
 */
public class Test {
    public static void main(String[] args) {
        /*HashMap<String,Integer> hashMap = new HashMap<>();
        hashMap.put("dfd",11);*/

        TreeSet<String> treeSet = new TreeSet<>();
        treeSet.add("sd");
    }
    public static void main2(String[] args) {
        TreeMap<String,Integer> treeMap = new TreeMap<>();
        treeMap.put("hello",12);
        treeMap.put("world",23);
        treeMap.put("abc",23);
        treeMap.put("abc",200);//key值不能重复，若重复会更新value值

        /*Integer i = treeMap.get("dfdfd");
        System.out.println(i);*/
        int i = treeMap.get("dfdfd");
        System.out.println(i);
    }
    public static void main1(String[] args) {
        TreeMap<String,Integer> treeMap = new TreeMap<>();
        treeMap.put("hello",12);
        treeMap.put("world",23);
        treeMap.put("abc",23);
        treeMap.put("abc",200);//key值不能重复，若重复会更新value值

        Set<String> set = treeMap.keySet();//得到key的Set集合
        for (String s : set) {
            System.out.print(s+" ");
        }
        System.out.println();
        Collection<Integer> collection = treeMap.values();//得到value的collection集合
        for (Integer integer : collection) {
            System.out.print(integer+" ");
        }
        System.out.println();
        Set<Map.Entry<String,Integer>> set1 = treeMap.entrySet();//得到key-value的Set集合
        for (Map.Entry<String, Integer> stringIntegerEntry : set1) {
            System.out.println("key："+stringIntegerEntry.getKey()+
                    " value："+stringIntegerEntry.getValue());
        }
        /*System.out.println(treeMap.get("abc"));//200
        //getOrDefault方法 若存在key则返回key对应的value  若不存在则返回默认值
        System.out.println(treeMap.getOrDefault("mama",100));//100
        treeMap.remove("world");
        System.out.println(treeMap.get("world"));//world已被删除 打印null*/
    }
}
